define([
  'jquery',
  'routers/Router',
  'models/Subscriber',
  'collections/Subscribers',
  'views/subscribers/SubscribersList',
  'views/subscribers/SubscriberDetail'
], function($, Router, Subscriber, Subscribers, SubscriberList, SubscriberDetail){
  var SubscriberRouter = Router.extend({
    routes: {

      "!/subscribers":       "subscribers",
      "!/subscriber/:id":   "detail",
      "!/subscribers/add":   "add"
    },
    
    subscribers: function() {
      console.log("Soy Subscribers index");
      //batzen.state.clearMessages();
      var subscribers = new Subscribers();
      subscribers.fetch();
      var subscribersView = new SubscriberList({collection: subscribers, messages: this.messages});
      $("#app").html(subscribersView.render().el);
    },

    detail: function(id) {
      //batzen.state.clearMessages();
      console.log("Detail of susbcriber with id: " + id);
      var subscriber = new Subscriber({id: id});
      subscriber.fetch();
      var view = new SubscriberDetail({model: subscriber});
      $("#app").html(view.render().el);
    },
    
    add: function() {
      console.log("Soy Subscribers add");
      var subscriber = new Subscriber();      
    }  
  });

  return SubscriberRouter;
});
